package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.domain.Strategy;
import cn.wolfcode.wolf2w.business.api.domain.StrategyEs;
import cn.wolfcode.wolf2w.business.repository.StrategyEsRepository;
import cn.wolfcode.wolf2w.common.core.utils.bean.BeanUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageServiceImpl {

    @Autowired
    private StrategyEsRepository repository;

    @RabbitListener(queues = {"strategyQueue"})
    public void onMessage(String message) {
        Strategy strategy = JSON.parseObject(message, Strategy.class);
        StrategyEs es = new StrategyEs();
        BeanUtils.copyProperties(strategy, es);
        repository.save(es);
    }
}
